
#include <gtest/gtest.h>
#include "01_KMP.h"

/**
 * @brief 函数单元测试checklist
 * 1、正常输入
 * 2、边界输入
 * 3、错误输入
 * 4、大数据量输入
 */

#if 0
TEST(txhKMP, getNext)
{
    txhKMP txhkmp;

	// 正常字符串
	EXPECT_TRUE(txhkmp.getNext("aabaa"));

    // 只有一个字符
	EXPECT_TRUE(txhkmp.getNext("a"));

    // 大小写
	EXPECT_TRUE(txhkmp.getNext("aA"));

    // 长字符串
	EXPECT_TRUE(txhkmp.getNext("aaaaaaaaaaaaaaaaaa"));

	// 空字符串
	EXPECT_FALSE(txhkmp.getNext(""));
}
#endif

TEST(txhKMP, strstr)
{
    txhKMP txhkmp;
    int ret = -1;

    // 单个字符子串，匹配成功
    ret = txhkmp.strStr("aabaa", "a");
    std::cout<<"ret:"<<ret<<std::endl;
    EXPECT_TRUE(-1 != ret);

    // 单个字符子串，匹配成功
    ret = txhkmp.strStr("aabaa", "b");
    std::cout<<"ret:"<<ret<<std::endl;
    EXPECT_TRUE(-1 != ret);

    // 两个字符子串，匹配成功
    ret = txhkmp.strStr("aabaa", "aa");
    std::cout<<"ret:"<<ret<<std::endl;
    EXPECT_TRUE(-1 != ret);

    // 两个字符子串，匹配成功
    ret = txhkmp.strStr("aabaa", "ab");
    std::cout<<"ret:"<<ret<<std::endl;
    EXPECT_TRUE(-1 != ret);

    ret = txhkmp.strStr("aabaa", "aabaa");
    std::cout<<"ret:"<<ret<<std::endl;
    EXPECT_TRUE(-1 != ret);

    ret = txhkmp.strStr("aabaabaaf", "aabaaf");
    std::cout<<"ret:"<<ret<<std::endl;
    EXPECT_TRUE(-1 != ret);

    ret = txhkmp.strStr("aabaa", "ac");
    std::cout<<"ret:"<<ret<<std::endl;
    EXPECT_TRUE(-1 == ret);

    ret = txhkmp.strStr("aabaaf", "aabaabaaf");
    std::cout<<"ret:"<<ret<<std::endl;
    EXPECT_TRUE(-1 == ret);

    ret = txhkmp.strStr("aabaaf", "");
    std::cout<<"ret:"<<ret<<std::endl;
    EXPECT_TRUE(-1 == ret);

    ret = txhkmp.strStr("", "");
    std::cout<<"ret:"<<ret<<std::endl;
    EXPECT_TRUE(-1 == ret);

    ret = txhkmp.strStr("aabaaf", nullptr);
    std::cout<<"ret:"<<ret<<std::endl;
    EXPECT_TRUE(-1 == ret);

    ret = txhkmp.strStr(nullptr, "aabaaf");
    std::cout<<"ret:"<<ret<<std::endl;
    EXPECT_TRUE(-1 == ret);
}


int main(int argc, char *argv[])
{
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
    return 0;
}

